/**
 * @param {number} n
 * @param {number} k
 * @return {number}
 */
 var findTheWinner = function(n, k) {
    let a = new Array(n)
    for(let i = 0; i<n; i++)
        a[i] = i+1
    let x = 0, count = 1, out = 0
    while(out < n-1){
        if(x >= a.length)
            x = 0
        if(count == k){
            a.splice(x--, 1)
            count = 0
            out++
        }
        count++
        x++
    }
    return a[0]
};